<template>
  <div class="container">
    <!--<el-row class="wrap-search">-->
    <!--<el-button @click="" type="primary" size="medium" @click="delAll">批量删除</el-button>-->
    <!--</el-row>-->
    <!--<el-row class="wrap-search">-->
    <!--<div class="search-item">-->
    <!--<div class="search-title">用户昵称：</div>-->
    <!--<el-input style="width: 200px;" class=""-->
    <!--placeholder="请输入用户昵称"-->
    <!--v-model="configList.param.nicknameLike" ></el-input>-->
    <!--</div>-->
    <!--<el-button  class="search-btn" type="primary" @click="getList()">查询</el-button>-->
    <!--</el-row>-->

    <el-row class="wrap-search">
      <div class="search-item">
        <div   class="search-title">订单号：</div>
        <el-input v-model="configList.param.order_no"></el-input>
      </div>
      <el-button
        icon="el-icon-search"
        class="search-btn"
        type="primary"
        @click="getList()"
      >查询</el-button>
    </el-row>
    <div class="">
      <table-list
        ref="tableList"
        :tableConfig='configList'
      >
        <!--<el-table-column-->
        <!--slot="select"  align="center" label="全选"-->
        <!--type="selection"-->
        <!--width="55">-->
        <!--</el-table-column>-->
        <el-table-column
          slot="image"
          align="center"
          label="用户头像"
        >
          <template slot-scope="scope">
            <!--<img class="video-img" :src="scope.row.avatarUrl" alt="">-->
            <div
              :style="{backgroundImage: 'url('+scope.row.avatarUrl+')'}"
              style="width: 60px;height: 60px;background-size: cover;border-radius: 30px;margin: 0 auto;"
            ></div>
          </template>
        </el-table-column>
        <el-table-column
          slot="created_at"
          align="center"
          label="时间"
        >
          <template slot-scope="scope">
            <div>{{_dateFormate(scope.row.created_at)}}</div>
          </template>
        </el-table-column>
        <el-table-column
          slot="address"
          min-width="220px"
          align="center"
          label="收货信息"
        >
          <template slot-scope="scope">
            <div>地址：{{scope.row.address && scope.row.address.address ? (
              scope.row.address.province+scope.row.address.city+scope.row.address.district+scope.row.address.street+scope.row.address.address
              ) : '--'}}
            </div>
            <div>电话：{{scope.row.address && scope.row.address.phone_num? scope.row.address.phone_num : '--'}}</div>
          </template>
        </el-table-column>
        <el-table-column
          slot="product"
          align="center"
          label="商品信息"
        >
          <template slot-scope="scope">
            <ul>
              <li
                v-for="(item, index) in scope.row.items"
                :key="index"
              >
                {{item.product_name}} X {{item.count}}
              </li>
            </ul>
          </template>
        </el-table-column>
        <el-table-column
          slot="status"
          align="center"
          label="订单状态"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0">未支付</div>
            <div v-else-if="scope.row.status == 1">已支付</div>
            <div v-else-if="scope.row.status == 2">已发货</div>
            <div v-else-if="scope.row.status == 3">已完成</div>
          </template>
        </el-table-column>
        <el-table-column
          class="btn"
          min-width="80px"
          label="操作"
          slot="btn"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              @click="handleShowDeliver(scope.row.order_id)"
              type="primary"
              size="medium"
              v-if="scope.row.status == 1"
            >发货</el-button>
            <!--<el-button  class="search-btn" size="small" type="danger" @click="delLevel(scope.row.id)">删除</el-button>-->
            <!-- <el-button v-if="scope.row.isRefundBtn == 'y'" class="search-btn" size="small" type="danger" @click="refundBtn(scope.row.id)">退款</el-button> -->
          </template>
        </el-table-column>
      </table-list>
    </div>
    <el-dialog
      title="请填写发货信息"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <el-form :model="form">
        <el-form-item
          label="物流公司"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="form.company"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="物流单号"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="form.express_no"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="handleDeliver"
        >确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
let CONSTANT = require("../constant/constant.js");
let common = require("../common.js");
import TableList from "./common/my-table";
export default {
  data() {
    return {
      configList: {
        url: CONSTANT.URL.orderList,
        configList: [
          {
            slot: "select"
          },
          {
            label: "订单编号",
            prop: "order_no",
            width: 200
          },
          {
            slot: "product"
          },
          {
            slot: "address"
          },
          {
            label: "购物金额",
            prop: "balance_cost"
          },
          {
            label: "获得积分",
            prop: "point_bonus"
          },
          {
            slot: "status"
          },
          { slot: "created_at" },
          {
            slot: "btn"
          }
        ],
        param: {
          nicknameLike: "",
          order_no:''
        },
        type: "",
        width: "",
        isPagination: true
      },
      dialogVisible: false,
      dialogVisible1: false,
      imgUrl: "",
      upLoadUrl: "",
      form: {
        express_no: "",
        company: ""
      },
      formLabelWidth: "100px",
      orderId: ""
    };
  },
  components: {
    "table-list": TableList
  },
  created() {},
  mounted() {},
  methods: {
    getList() {
      this.$refs.tableList.getList();
    },
    _dateFormate(value) {
      return common.dateFormate(value);
    },
    handleShowDeliver(order_id) {
      this.orderId = order_id;
      this.dialogVisible = true;
    },
    handleDeliver() {
      if (!this.form.express_no) {
        this.$message({
          type: "warning",
          message: "请填写快递单号"
        });
        return false;
      }
      if (!this.form.company) {
        this.$message({
          type: "warning",
          message: "请填写物流公司"
        });
        return false;
      }
      let url = CONSTANT.URL.orderExpress,
        param = Object.assign({ order_id: this.orderId }, this.form);
      common.requestAjax(url, param, {}, res => {
        if (res.status == 0) {
          this.$message({
            type: "success",
            message: "发货成功"
          });
          this.dialogVisible = false;
          this.getList();
        } else {
          this.$message({
            message: res.msg,
            type: "warning"
          });
        }
      });
    }
  }
};
</script>

<style lang="scss">
.container {
  .wrap-search {
    margin-bottom: 20px;
    .search-item {
      float: left;
      margin-right: 20px;
      margin-top: 20px;
      .el-input,
      .el-select {
        width: 180px;
      }
    }
    button {
      float: left;
      margin-top: 20px;
    }
    .search-title {
      display: inline;
      width: 100px;
      height: 36px;
      line-height: 36px;
      text-align: right;
      margin-bottom: 20px;
      margin-right: 10px;
    }
  }
  .el-table__row {
    .cell {
      button {
        margin-top: 10px;
      }
    }
    video {
      width: 100px;
      height: auto;
    }
    img.video-img {
      width: 60px;
      height: 60px;
      cursor: pointer;
      border-radius: 30px;
    }
  }
  .pagination {
    text-align: center;
    width: 80%;
    margin-top: 60px;
  }
  .el-dialog__body {
    img {
      display: block;
      margin: 0 auto;
    }
  }
  .user-num {
    color: #409eff;
    cursor: pointer;
  }

  .avatar {
    width: 50px !important;
    height: 50px;
    border-radius: 50%;
    -webkit-border-radius: 50%;
  }
}
</style>
